//
//  ZTAlbumDetailTableViewCell.m
//  XMLYFM
//
//  Created by dllo on 15/12/26.
//  Copyright © 2015年 zzl. All rights reserved.
//

#import "ZTAlbumDetailTableViewCell.h"
#import <UIImageView+WebCache.h>
#import <Masonry.h>

#define WIDTH [[UIScreen mainScreen] bounds].size.width

#define HEIGHT [[UIScreen mainScreen] bounds].size.height

@implementation ZTAlbumDetailTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createCell];
    }
    
    return self;
}

-(void)createCell
{
    
    
    self.trackPic = [UIImageView new];
    self.trackPic.backgroundColor = [UIColor whiteColor];
    self.trackPic.layer.masksToBounds = YES;
    self.trackPic.layer.cornerRadius = 25;
    [self.contentView addSubview:self.trackPic];
    
    [self.trackPic mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.contentView).offset(15);
        make.top.equalTo(self.contentView).offset(10);
        make.width.offset(50);
        make.height.offset(50);
        
    }];
    
    
    
    
    self.playButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.playButton.frame = CGRectMake(self.contentView.bounds.origin.x + 15, self.contentView.bounds.origin.y + 10, 20, 20);
    self.playButton.backgroundColor = [UIColor clearColor];
    self.playButton.alpha = 0.5;
    self.playButton.center = self.trackPic.center;
    [self.playButton setImage:[UIImage imageNamed:@"cell_sound_play_n@2x.png"] forState:UIControlStateNormal];
    [self.contentView addSubview:self.playButton];
    
    
    

    self.trackTitle = [UILabel new];
    self.trackTitle.font = [UIFont systemFontOfSize:13 weight:0];
    self.trackTitle.numberOfLines = 2;
    [self.contentView addSubview:self.trackTitle];
    
    [self.trackTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.trackPic.mas_right).offset(10);
        make.top.equalTo(self.contentView).offset(10);
        make.width.offset(250);
        make.height.offset(30);
        
    }];

    
    
    
    self.trackDigest = [UILabel new];
    self.trackDigest.backgroundColor = [UIColor clearColor];
    self.trackDigest.font = [UIFont systemFontOfSize:11 weight:0];
    [self.contentView addSubview:self.trackDigest];
    self.trackDigest.textColor = [UIColor lightGrayColor];

    
    
    self.iconImageV = [UIImageView new];
    self.iconImageV.backgroundColor = [UIColor clearColor];
    self.iconImageV.image = [UIImage imageNamed:@"album_playCountLogo@2x.png"];
    [self.contentView addSubview:self.iconImageV];
    

    
    self.playCount = [UILabel new];
    self.playCount.backgroundColor = [UIColor clearColor];
    self.playCount.font = [UIFont systemFontOfSize:11 weight:0];
    [self.contentView addSubview:self.playCount];
    self.playCount.textAlignment = NSTextAlignmentRight;
    self.playCount.textColor = [UIColor lightGrayColor];
    
    

    
    self.iconLikeV = [UIImageView new];
    self.iconLikeV.backgroundColor = [UIColor clearColor];
    self.iconLikeV.image = [UIImage imageNamed:@"find_emotion@2x.png"];
    [self.contentView addSubview:self.iconLikeV];
    
    
    
    //时长
    self.duration = [UILabel new];
    self.duration.backgroundColor = [UIColor clearColor];
    self.duration.font = [UIFont systemFontOfSize:11 weight:0];
    [self.contentView addSubview:self.duration];
    self.duration.textAlignment = NSTextAlignmentRight;
    self.duration.textColor = [UIColor lightGrayColor];
    
    
    //下载按钮
    self.downloadBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.downloadBtn.frame = CGRectMake(self.contentView.bounds.size.width, self.contentView.bounds.size.height, 20, 20);
    self.downloadBtn.backgroundColor = [UIColor clearColor];
    [self.downloadBtn setImage:[UIImage imageNamed:@"cell_download@2x.png"] forState:UIControlStateNormal];
    [self.contentView addSubview:self.downloadBtn];

    
    
}

-(void)setTrackModel:(ZTTrackModel *)trackModel
{
    
        _trackModel = trackModel;
    
    
    NSURL *url = [NSURL URLWithString:trackModel.coverSmall];
    [self.trackPic sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"loading.jpg"]];
    
    self.trackTitle.text = trackModel.title;
    [self.trackTitle sizeToFit];
    
    
    self.trackDigest.text = [NSString stringWithFormat:@"by %@", trackModel.nickname];
    [self.trackDigest mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.trackPic.mas_right).offset(10);
        make.top.equalTo(self.trackTitle.mas_bottom).offset(5);
        make.width.offset(200);
        make.height.offset(10);
        
    }];
    
    
    
    [self.iconImageV mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.trackPic.mas_right).offset(10);
        make.top.equalTo(self.trackDigest.mas_bottom).offset(10);
        make.width.offset(HEIGHT * 0.016);
        make.height.offset(HEIGHT * 0.016);
        
        
    }];
    
    
    self.playCount.text = [NSString stringWithFormat:@"%.2f万", (CGFloat)trackModel.playtimes / 10000];
    [self.playCount mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.trackPic.mas_right).offset(10);
        make.top.equalTo(self.trackDigest.mas_bottom).offset(10);
        make.width.offset(50);
        make.height.offset(10);
        
    }];
    
    
    [self.iconLikeV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.playCount.mas_right).offset(10);
        make.top.equalTo(self.trackDigest.mas_bottom).offset(10);
        make.width.offset(HEIGHT * 0.02);
        make.height.offset(HEIGHT * 0.02);
        
    }];
    
    
    self.duration.text = [NSString stringWithFormat:@"%ld人想听", trackModel.likes];
    [self.duration sizeToFit];
    [self.duration mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.iconLikeV.mas_right).offset(10);
        make.top.equalTo(self.playCount.mas_bottom).offset(-10);
        make.width.offset(100);
        make.height.offset(10);
        
    }];
    
    
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
